﻿@using Microsoft.AspNetCore.Components.Routing
@using Components.WasmMinimal.Pages.NotFound
@inject NavigationManager NavigationManager

@code {
    [Parameter]
    [SupplyParameterFromQuery(Name = "useCustomNotFoundPage")]
    public string? UseCustomNotFoundPage { get; set; }

    private Type? NotFoundPageType { get; set; }

    protected override void OnParametersSet()
    {
        if (UseCustomNotFoundPage == "true")
        {
            NotFoundPageType = typeof(CustomNotFoundPage);
        }
        else
        {
            NotFoundPageType = null;
        }
    }
}

<Router AppAssembly="@typeof(Program).Assembly" NotFoundPage="NotFoundPageType">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" />
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
    <NotFound>There's nothing here</NotFound>
</Router>
